package com.itheima.pinda.impl.user;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.pinda.DTO.entity.dto.PdTruckDriverDTO;
import com.itheima.pinda.DTO.entity.pojo.agency.PdFleet;
import com.itheima.pinda.DTO.entity.pojo.user.PdTruckDriver;
import com.itheima.pinda.feign.service.agency.PdFleetService;
import com.itheima.pinda.feign.service.user.PdTruckDriverService;
import com.itheima.pinda.mapper.user.PdTruckDriverMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 司机表 服务实现类
 * </p>
 *
 * @author xy
 * @since 2021-11-12
 */
@Service
public class PdTruckDriverServiceImpl extends ServiceImpl<PdTruckDriverMapper, PdTruckDriver> implements PdTruckDriverService {


    @Autowired
    private PdFleetService fleetService;

    @Override
    public Integer findByFleet(String fid) {
        if (ObjectUtils.isEmpty(fid)){
            throw  new NullPointerException("你传的车队编号为空");
        }
        QueryWrapper<PdTruckDriver> wrapper = new QueryWrapper<>();
        wrapper.eq("fleet_id",fid);
        Integer count = super.baseMapper.selectCount(wrapper);
        return count;
    }

    @Override
    public List<PdTruckDriverDTO> findAll(String driverid, String licensePlate) {

        QueryWrapper<PdTruckDriver> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",driverid);
        List<PdTruckDriver> driverList = super.baseMapper.selectList(wrapper);

        List<PdTruckDriverDTO> truckDriverDTOS = new ArrayList<>();

        for (PdTruckDriver truckDriver: driverList
             ) {
            PdTruckDriverDTO dto = new PdTruckDriverDTO();
            BeanUtils.copyProperties(truckDriver,dto);

            QueryWrapper<PdFleet> fleetQueryWrapper = new QueryWrapper<>();
            fleetQueryWrapper.eq("id", driverid);
            PdFleet fleet = fleetService.getBaseMapper().selectOne(fleetQueryWrapper);




        }

        return truckDriverDTOS;
    }


}
